package com.cy.阿里上机测试.Test03;

class TestThread extends Thread {
    private static int flag = 1;
    private final int curFlag;

    public TestThread(String name, int curFlag) {
        this.curFlag = curFlag;
        super.setName(name);
    }

    @Override
    public void run() {
        int count = 1;
        while (count <= 10) {
            if (curFlag == flag) {
                System.out.print(getName());
                if (flag == 3) {
                    flag = 1;
                } else {
                    synchronized (TestThread.class) {
                        flag++;
                    }
                }
                count++;
            }
        }
    }
}